<?php
/**
 * Auth_model Class
 *
 */
class Auth_model extends CI_Model {
	/**
	 * Constructor
	 */
	function Auth_model()
		{
			parent::__construct();
		}
		
	// Inisialisasi nama tabel user
	var $table = 'user';
	
	/**
	 * Cek tabel user, apakah ada user dengan username, password tertentu
	 */
	function check_user($username, $password)
	{
		$post_password = md5($this->input->post('password', TRUE));
		$query = $this->db->get_where($this->table, array('username' => $username, 'password' => $post_password), 1, 0);
		
		if ($query->num_rows() > 0)
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	
	function get_logged_user($username)
	{
		$this->db->select('user.id_user, user.id_role, user.username, user.password, user.nama');
		$this->db->from($this->table);
		$this->db->where('user.username', $username);
		return $this->db->get()->result();
	}
	
		
	function get_hak_akses($id_role)
	{
		$this->db->select('hak_akses.id_fitur, hak_akses.id_role, fitur.nama_fitur');
		$this->db->from('hak_akses');
		$this->db->where('hak_akses.id_role', $id_role);
		$this->db->join('fitur', 'hak_akses.id_fitur = fitur.id_fitur');
		return $this->db->get()->result();
	}
	
	function get_user($id){
		$this->db->select('*');
		$this->db->from('user');
		$this->db->where('ID_USER', $id);
		
		return $this->db->get();
	}
}
// END Auth_model Class

/* End of file Auth_model.php */ 
/* Location: ./system/application/model/Auth_model.php */